﻿Namespace Graphics
    Public Module Graphics
        Public Sub DrawRoundedRectangle(ByVal g As System.Drawing.Graphics, ByVal pen As System.Drawing.Pen, ByVal roundedRectangle As System.Drawing.Rectangle, ByVal cornerSize As System.Drawing.Size, ByVal FillColor As System.Drawing.Color)
            Dim points(7) As System.Drawing.Point
            Dim rX As Single = roundedRectangle.Location.X
            Dim rY As Single = roundedRectangle.Location.Y
            Dim rW As Single = roundedRectangle.Width
            Dim rH As Single = roundedRectangle.Height
            Dim cW As Single = cornerSize.Width
            Dim cH As Single = cornerSize.Height
            ' Prepara i punti per le linee
            points(0) = New System.Drawing.Point(rX + cW / 2, rY)
            points(1) = New System.Drawing.Point(rX + rW - cW, rY)
            points(2) = New System.Drawing.Point(rX + rW, rY + cH / 2)
            points(3) = New System.Drawing.Point(rX + rW, rY + rH - cH)
            points(4) = New System.Drawing.Point(rX + rW - cW, rY + rH)
            points(5) = New System.Drawing.Point(rX + cW / 2, rY + rH)
            points(6) = New System.Drawing.Point(rX, rY + rH - cH)
            points(7) = New System.Drawing.Point(rX, rY + cH / 2)
            Dim rectPath As New System.Drawing.Drawing2D.GraphicsPath
            rectPath.StartFigure()
            rectPath.AddLine(points(0), points(1))
            rectPath.AddArc(rX + rW - cW, rY, cW, cH, CType(270, Single), CType(90, Single))
            rectPath.AddLine(points(2), points(3))
            rectPath.AddArc(rX + rW - cW, rY + rH - cH, cW, cH, CType(0, Single), CType(90, Single))
            rectPath.AddLine(points(4), points(5))
            rectPath.AddArc(rX, rY + rH - cH, cW, cH, CType(90, Single), CType(90, Single))
            rectPath.AddLine(points(6), points(7))
            rectPath.AddArc(rX, rY, cW, cH, CType(180, Single), CType(90, Single))
            rectPath.CloseFigure()
            g.FillPath(New System.Drawing.SolidBrush(FillColor), rectPath)
            g.DrawPath(pen, rectPath)
        End Sub

    End Module
End Namespace
